<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./moduleControl.xhtml">

            <ui:define name="tabContent">
                <h:form>
                    <h:panelGrid columns="2">
                        <p:selectOneMenu value="#{moduleConfigBean.selectedModule}">
                            <f:selectItems value="#{moduleConfigBean.moduleMap}"/>
                        </p:selectOneMenu>
                        <p:commandButton ajax="false" value="Chọn module" action="#{moduleConfigBean.filterByModule()}"/>
                    </h:panelGrid>
                </h:form>

                <h:form>
                    <p:panel>
                        <table border="0" cellspacing="5">
                            <tbody>
                                <tr>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Id      <p:inputText value="#{moduleConfigBean.selected.configId}" disabled="true"/>
                                            Khóa*     <p:inputText value="#{moduleConfigBean.selected.configKey}"
                                                                   required="true" requiredMessage="Bạn chưa điền khóa"/>
                                            Giá trị*    <p:inputText value="#{moduleConfigBean.selected.configValue}"
                                                                     required="true" requiredMessage="Bạn chưa điền giá trị"/>
                                        </h:panelGrid>
                                    </td>
                                    <td style="vertical-align: top">
                                        <h:panelGrid columns="2">
                                            Module*    <p:inputText value="#{moduleConfigBean.selected.moduleName}"
                                                                    required="true" requiredMessage="Bạn chưa điền tên module"/>
                                            Mô tả <p:inputTextarea value="#{moduleConfigBean.selected.description}"/>
                                            Id cấp trên 
                                            <p:selectOneMenu value="#{moduleConfigBean.selectedParentId}">
                                                <f:selectItems value="#{moduleConfigBean.configMap}"/>
                                            </p:selectOneMenu>
                                        </h:panelGrid>
                                    </td>
                                </tr>
                            </tbody>
                        </table>

                        <h:panelGrid columns="5">
                            <p:commandButton ajax="false" value="Thêm mới" rendered="#{!moduleConfigBean.edit}" action="#{moduleConfigBean.create()}"/>
                            <p:commandButton ajax="false" value="Cập nhật" rendered="#{moduleConfigBean.edit}" action="#{moduleConfigBean.edit()}"/>
                            <p:commandButton ajax="false" value="Hủy bỏ" immediate="true" action="#{moduleConfigBean.resetToCreateForm()}"/>
                        </h:panelGrid>
                    </p:panel>
                </h:form>
                <br/>
                <h:form>
                    <p:dataTable id="table" value="#{moduleConfigBean.list}" var="item" paginator="#{moduleConfigBean.list.size() >20}" rows="20" 
                                 selection="#{moduleConfigBean.selectedList}"  selectionMode="multiple">

                        <f:facet name="header">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{moduleConfigBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="configDeleteConfirm.show();" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <f:facet name="footer">  
                            <div align="left">
                                <p:menuButton value="Xử lý bản ghi được chọn">  
                                    <p:menuitem ajax="false" value="Chỉnh sửa" icon="ui-icon ui-icon-pencil" action="#{moduleConfigBean.prepareEdit()}"/>
                                    <p:menuitem value="Xóa" icon="ui-icon ui-icon-close" onclick="configDeleteConfirm.show();" />   
                                </p:menuButton> 
                            </div>
                        </f:facet> 

                        <p:column headerText="Id" sortBy="#{item.configId}">
                            #{item.configId}
                        </p:column>
                        <p:column headerText="Module" sortBy="#{item.moduleName}">
                            #{item.moduleName}
                        </p:column>
                        <p:column headerText="Khóa" sortBy="#{item.configKey}">
                            #{item.configKey}
                        </p:column>
                        <p:column headerText="Giá trị" sortBy="#{item.configValue}">
                            #{item.configValue}
                        </p:column>
                        <p:column headerText="Mô tả" sortBy="#{item.description}">
                            #{item.description}
                        </p:column>
                        <p:column headerText="Id cấp trên" sortBy="#{item.parentConfigId.configId}">
                            #{item.parentConfigId.configId}
                        </p:column>
                    </p:dataTable>
                    <p:confirmDialog message="Bạn muốn xóa các bản ghi đã chọn?"  
                                     header="Xác nhận" severity="alert" widgetVar="configDeleteConfirm">  

                        <p:commandButton update="table" value="Có" oncomplete="configDeleteConfirm.hide()"  
                                         action="#{moduleConfigBean.remove()}"/>
                        <p:commandButton value="Không" onclick="configDeleteConfirm.hide();" type="button" />   

                    </p:confirmDialog> 
                </h:form>

            </ui:define>

        </ui:composition>

    </body>
</html>
